package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtSmsLog;
import com.ruoyi.business.service.IJtSmsLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信记录Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-31
 */
@Controller
@RequestMapping("/business/sms")
public class JtSmsLogController extends BaseController
{
    private String prefix = "business/sms";

    @Autowired
    private IJtSmsLogService jtSmsLogService;

    @RequiresPermissions("business:sms:view")
    @GetMapping()
    public String sms()
    {
        return prefix + "/sms";
    }

    /**
     * 查询短信记录列表
     */
    @RequiresPermissions("business:sms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtSmsLog jtSmsLog)
    {
        startPage();
        List<JtSmsLog> list = jtSmsLogService.selectJtSmsLogList(jtSmsLog);
        return getDataTable(list);
    }

    /**
     * 导出短信记录列表
     */
    @RequiresPermissions("business:sms:export")
    @Log(title = "短信记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtSmsLog jtSmsLog)
    {
        List<JtSmsLog> list = jtSmsLogService.selectJtSmsLogList(jtSmsLog);
        ExcelUtil<JtSmsLog> util = new ExcelUtil<JtSmsLog>(JtSmsLog.class);
        return util.exportExcel(list, "短信记录数据");
    }

    /**
     * 新增短信记录
     */
    @RequiresPermissions("business:sms:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信记录
     */
    @RequiresPermissions("business:sms:add")
    @Log(title = "短信记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtSmsLog jtSmsLog)
    {
        return toAjax(jtSmsLogService.insertJtSmsLog(jtSmsLog));
    }

    /**
     * 修改短信记录
     */
    @RequiresPermissions("business:sms:edit")
    @GetMapping("/edit/{smsId}")
    public String edit(@PathVariable("smsId") Long smsId, ModelMap mmap)
    {
        JtSmsLog jtSmsLog = jtSmsLogService.selectJtSmsLogBySmsId(smsId);
        mmap.put("jtSmsLog", jtSmsLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信记录
     */
    @RequiresPermissions("business:sms:edit")
    @Log(title = "短信记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtSmsLog jtSmsLog)
    {
        return toAjax(jtSmsLogService.updateJtSmsLog(jtSmsLog));
    }

    /**
     * 删除短信记录
     */
    @RequiresPermissions("business:sms:remove")
    @Log(title = "短信记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtSmsLogService.deleteJtSmsLogBySmsIds(ids));
    }
}
